package org.hackystat.ui.chart.jfc.chartresource.dataset;

import static org.junit.Assert.assertEquals;

import java.awt.geom.Point2D;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

import org.junit.Before;
import org.junit.Test;

/**
 * Tests DataFactoryImpl.
 *
 * @author Pavel Senin.
 *
 */
public class TestDataFactoryImpl {

  DataFactoryImpl df;
  DateFormat dFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.US);

  /**
   * Runs before each test to make a fixture.
   *
   * @throws Exception when test doesn't want to work.
   */
  @Before
  public void setUp() throws Exception {
    df = new DataFactoryImpl();
  }

  /**
   * Tests the get data methods.
   *
   * @throws ParseException if get an error.
   */
  @Test
  public void testGetData() throws ParseException {

    Date startDate = dFormat.parse("May 1, 2007");

    Date endDate = dFormat.parse("May 2, 2007");
    ArrayList<Point2D.Double> testData = df
        .getData("test", "dependency", "afferentCouplings", startDate, endDate, "day");
    assertEquals("testing dataset size", 1, testData.size());

    endDate = dFormat.parse("May 8, 2007");
    testData = df.getData("test", "dependency", "efferentCouplings", startDate, endDate, "day");
    assertEquals("testing dataset size", 7, testData.size());

    endDate = dFormat.parse("June 1, 2007");
    testData = df.getData("test", "dependency", "cycles",startDate, endDate, "day");
    assertEquals("testing dataset size", 31, testData.size());
  }

}
